import {
  getMvDetailById,
  getMvUrlById,
  getMvRelatedDataById,
} from "../../service/api-video";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    videoId: 0,
    mvUrlInfo: {},
    videoInfo: {},
    mvDetailVideos: [],
    danmuList: [
      {
        text: "第 1s 出现的弹幕",
        color: "#ff0000",
        time: 1,
      },
      {
        text: "第 3s 出现的弹幕",
        color: "#ff00ff",
        time: 3,
      },
      {
        text: "hzy，i love you",
        color: "pink",
        time: 3,
      },
      {
        text: "hzy，i love you",
        color: "green",
        time: 3,
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { videoId } = options;
    this.fetchMvUrl(videoId);
    this.fetchVideoInfo(videoId);
    this.fetchRelate(videoId);
  },

  // 请求播放地址
  async fetchMvUrl(videoId) {
    try {
      const res = await getMvUrlById(videoId);
      this.setData({ mvUrlInfo: res.data });
    } catch (error) {
      wx.showToast({
        title: error.message,
      });
    }
  },
  // 请求视频信息
  async fetchVideoInfo(videoId) {
    try {
      const res = await getMvDetailById(videoId);
      this.setData({ videoInfo: res.data });
    } catch (error) {
      wx.showToast({
        title: error.message,
      });
    }
  },
  // 请求相关信息
  async fetchRelate(videoId) {
    try {
      const res = await getMvRelatedDataById(videoId);
      this.setData({ mvDetailVideos: res.data });
    } catch (error) {
      wx.showToast({
        title: error.message,
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
